﻿<cfinclude template="/code_lib/SCF_ActiveDirectory.cfc">
<cfinclude template="/code_lib/SCF_Exchange.cfm" />
<cfset Badge = CreateObject("component", "Badges").init() />
<cfset ps = CreateObject("component", "code_lib.SCF_PowerShell")/>
<!---<cfset GroupDN = getGroupDNByDisplayName("SCF Information Technology Services") />--->
<cfset GroupDN = getGroupDNByDisplayName("SCF VPs DL") />
<cfset Employees = SCF_Exchange_GetEmployeesInDL(GroupDN) />
<cfset EmpStruct = StructNew() />

<cfloop from="1" to="#ArrayLen(Employees)#" index="e">
    <cfif Employees[e].RosettaID NEQ 0 >
        <cfset EmpStruct[#Employees[e].login#] =  {
            RosettaID = #Employees[e].RosettaID# ,  
            HR_PersonIDNO = #Employees[e].HR_PERSONIDNO#, 
            BadgePic = "#Badge.getBadgeDirectory()#thumbs\#listGetAt(Badge.getEmployeeBadge( Employees[e].RosettaID ).PhotoFileName, '5', '\')#"
        } />
    </cfif>
</cfloop>

<cfdump var="#EmpStruct#" expand="false">

<cfloop collection="#EmpStruct#" item="key">
       
        <cfif EmpStruct[key].BadgePic NEQ "">
            <cfscript>
                
                result = ps.usePowerShell('add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
                $user = Get-User "' & key & '" -ErrorAction SilentlyContinue;
                $FileData = [Byte[]]$(Get-Content -Path "' & EmpStruct[key].BadgePic & '" -Encoding Byte -ReadCount 0);
                $adsiuser = [ADSI]"LDAP://$($user.OriginatingServer)/$($user.DistinguishedName)";
                $adsiuser.Put("thumbnailPhoto", $FileData);
                $adsiuser.SetInfo();
                ');
                //writeDump(result);
            </cfscript>
        </cfif>              
    
  
</cfloop>





<!---<cfset imgs = {bfrick = '', kapplegate = '', jatuk = '', jkrull = '', jkyle = '', rdemott = '', rwolcoff = '', dmlewis = ''} />--->

<!---<cfoutput>
    <cfloop collection="#imgs#" item="key">
       <cftry>
       	<cfscript>
	            powershell = CreateObject("webservice", "http://scfcas/PowerShellService/?WSDL");
	            result = powershell.Invoke('add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
	            $user = Get-User "' & key & '" -ErrorAction SilentlyContinue;
	            $FileData = [Byte[]]$(Get-Content -Path "' & imgs[key] & '" -Encoding Byte -ReadCount 0);
	            $adsiuser = [ADSI]"LDAP://$($user.OriginatingServer)/$($user.DistinguishedName)";
	            $adsiuser.Put("thumbnailPhoto", $FileData);
	            $adsiuser.SetInfo();
	            ');
        </cfscript>        
        <cfset dn = getUserDNByAccountName(key) />
        <cfset x = getUserAttributesByDN(dn, "thumbnailPhoto,cn,sn,ldapDisplayName,title,description") />
        <cfset replaceAttributesByDN( dn, 'thumbnailPhoto=') />
        <cfdump var="#x#" />       
       <cfcatch type="Any" >
            <cfdump var="#CFCATCH#">
       </cfcatch>
       </cftry>

    </cfloop>
</cfoutput>--->

<!---<cfscript>
powershell = CreateObject("webservice", "http://scfcas/PowerShellService/?WSDL");
result = powershell.Invoke('add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
$user = Get-User "bfrick" -ErrorAction SilentlyContinue;
$FileData = [Byte[]]$(Get-Content -Path "\\SCFUserShare\Home\bfrick\token.jpg" -Encoding Byte -ReadCount 0);
$adsiuser = [ADSI]"LDAP://$($user.OriginatingServer)/$($user.DistinguishedName)";
$adsiuser.Put("thumbnailPhoto", $FileData);
$adsiuser.SetInfo();
');
/*result = powershell.Invoke('add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin, Microsoft.Windows.AD
get-mailbox XXXTestXXX | out-string -width 10000
$photo = [byte[]](Get-Content \\SCFUserShare\Home\bficrk\token.jpg  -Encoding byte)
Set-ADUser bfrick -Replace @{thumbnailPhoto=$photo}
');*/
/*writeDump(result);*/
</cfscript>--->
<!---
<cfinclude template="/code_lib/SCF_ActiveDirectory.cfc">
<cfset dn = getUserDNByAccountName('bfrick') />
<cfset x = getUserAttributesByDN(dn, "thumbnailPhoto,cn,sn,ldapDisplayName,title,description") />
<cfdump var="#x#" />
<!---<cfset replaceAttributesByDN( dn, 'thumbnailPhoto=\\SCFUserShare\Home\bfrick\token.jpg') />--->
<!---<cfset replaceAttributesByDN( dn, 'thumbnailPhoto=#toBase64("\\SCFUserShare\Home\bfrick\token.jpg")#') />--->
<cfset x = getUserAttributesByDN(dn, "thumbnailPhoto,cn,sn,ldapDisplayName,title,description") />
<!---<cfset x = getUserAttributesByDN(dn, "thumbnailPhoto,cn,sn,ldapDisplayName,title,description,department,manager,wWWHomePage,displayName,member,dn,userAccountControl,homeDirectory,homeDrive,msExchHideFromAddressLists,givenName,initials,sn,userPrincipalName,sAMAccountName,whenChanged") />--->
<cfdump var="#ToBase64(x.thumbnailPhoto)#" />
<cffile action="readBinary" file="\\SCFUserShare\Home\bfrick\token.jpg" variable = "CopyOfPic"  />
<!---<cfdump var="#toString(CopyOfPic)#">--->
<!---<cfset replaceAttributesByDN( dn, 'thumbnailPhoto=#CopyOfPic#') />--->
--->


<!--- <cfquery name="FirstLook" datasource="RosettaProd">
SELECT     r.RosettaID, biw.BadgeNumber, biw.PhotoFileName, biw.CardType, iv.IDX, iv.PHOTO, iv.LAST_NAME, iv.FIRST_NAME
FROM         RosettaStone AS r INNER JOIN
                      Badge_IDWorks.Badges AS biw ON r.RosettaID = biw.RosettaID INNER JOIN
                      IVISPLUS.dbo.IVIS_DATA AS iv ON r.IVIS_IDX = iv.IDX
WHERE     (biw.PhotoFileName IS NULL)
</cfquery>
<cfset badgeworkpath = '\\scfappshare\ITS_Data\IDCentre\BadgePhotos\' />

<cfset photoarray = ArrayNew(2)>
                    
<cfloop query="FirstLook">
    <cfset photoarray[CurrentRow][1] = photo>
    <cfset photoarray[CurrentRow][2] = first_name>
    <cfset photoarray[CurrentRow][3] = last_name>
    <cfset photoarray[CurrentRow][5] = department>
    <cfset photoarray[CurrentRow][4] = company>
    <cfset photoarray[CurrentRow][6] = id_card_num>
    <cfset photoarray[CurrentRow][7] = idx>
    <cfset photoarray[CurrentRow][8] = RosettaID>
</cfloop>
<cfoutput>#FirstLook.RecordCount#</cfoutput>
<table width="100%" border='1'>
<tr>
<td>badge location</td>
<td>IDX</td>
<td>Card ID</td>
<td>Employee</td>
<td>RosettaID</td>
</tr>

<cfloop from="1" to="#FirstLook.RecordCount#" index="x">
<cftry>
        <cfoutput>
            <cfset folder = Right(photoarray[x][1],Len(photoarray[x][1])-1)>
            <cfset folder = Left(folder, Len(folder)-3)/500>
            <cfset picfolder = Int(folder)+1>
            <tr>
            <td>&nbsp;pic#picfolder#\#photoarray[x][1]#</td>            
            <td>&nbsp;#photoarray[x][7]#</td>
            <td>&nbsp;#photoarray[x][6]#</td>
            <td>&nbsp;#photoarray[x][2]# #photoarray[x][3]#</td>
            <td>&nbsp;#photoarray[x][8]#</td>
            </tr>
        </cfoutput>
<cfcatch type="Any" >

</cfcatch>
</cftry>

</cfloop>

</table> --->


<!---<cfquery name="FirstLook" datasource="RosettaStone" maxrows="10">
SELECT     r.RosettaID, biw.BadgeNumber, biw.PhotoFileName, biw.CardType, iv.IDX, iv.PHOTO, iv.LAST_NAME, iv.FIRST_NAME, iv.ID_CARD_NUM, iv.Department, iv.Company
FROM         RosettaStone AS r INNER JOIN
          Badge_IDWorks.dbo.Badges AS biw ON r.RosettaID = biw.RosettaID INNER JOIN
          IVISPLUS.dbo.IVIS_DATA AS iv ON r.IVIS_IDX = iv.IDX
WHERE     (biw.PhotoFileName IS NULL)
</cfquery>
<cfset ivsPath = '\\scfappshare\ITS_Data\applications\ivisplus\photos' />
<Cfset badgeWorksPath = "\\scfappshare\ITS_Data\IDCentre\BadgePhotos" />

<cfset oldbadgepath = '\\SCFUserShare\Home\bfrick\badge' />
<cfset newbadgepath = '\\SCFUserShare\Home\bfrick\test' />
<!---<cffile action = "readBinary" 
    file = "\\SCFUserShare\Home\bfrick\badge\pic1\p22.pc" variable = "x">

<cffile action="write" file="\\SCFUserShare\Home\bfrick\test\hello.jpg" output="#x#" >--->
    
<cfset photoarray = ArrayNew(2)>
                    
<cfloop query="FirstLook">
    <cfset photoarray[CurrentRow][1] = photo>
    <cfset photoarray[CurrentRow][2] = first_name>
    <cfset photoarray[CurrentRow][3] = last_name>
    <cfset photoarray[CurrentRow][5] = department>
    <cfset photoarray[CurrentRow][4] = company>
    <cfset photoarray[CurrentRow][6] = id_card_num>
    <cfset photoarray[CurrentRow][7] = idx>
    <cfset photoarray[CurrentRow][8] = RosettaID>
</cfloop>
<cfoutput>#FirstLook.RecordCount#</cfoutput>
<table width="100%" border='1'>
<tr>
<td>Employee</td>
<td>RosettaID</td>
<td>badge location</td>
<td>IDX</td>
<td>Card ID</td>

</tr>

<cfloop from="1" to="#FirstLook.RecordCount#" index="x" >
<cftry>
        <cfoutput>
            <cfset folder = Right(photoarray[x][1],Len(photoarray[x][1])-1)>
            <cfset folder = Left(folder, Len(folder)-3)/500>
            <cfset picfolder = Int(folder)+1>
            <tr>
            <td>&nbsp;#photoarray[x][2]# #photoarray[x][3]#</td>
            <td>&nbsp;#photoarray[x][8]#</td>
            <td>&nbsp;pic#picfolder#\#photoarray[x][1]#</td>            
            <td>&nbsp;#photoarray[x][7]#</td>
            <td>&nbsp;#photoarray[x][6]#</td>            
            </tr>
            <cffile action="readBinary" file="#oldbadgepath#\pic#picfolder#\#photoarray[x][1]#" variable = "CopyOfPic" />
            <cfset newPic = Replace("#newbadgepath#\#photoarray[x][2]#_#photoarray[x][3]#_#photoarray[x][8]#.jpg",',', '_', "All") />
            <cffile action="write" file="#newPic#" output="#CopyOfPic#" />
        </cfoutput>
<cfcatch type="Any" >

</cfcatch>
</cftry>

</cfloop>

</table>
--->



<!---
<cfset powershell = CreateObject("webservice", "http://scfcas/PowerShellService/?WSDL") />
<cfset result = powershell.invoke('add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
get-mailbox bfrick | out-string -width 10000
') />
<cfoutput>#powershell#</cfoutput>--->
<!---<cfscript>
powershell = CreateObject("webservice", "http://scfcas/PowerShellService/?WSDL");
result = powershell.Invoke('add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
get-mailbox bfrick | out-string -width 10000
');
writeDump(powershell);
</cfscript>--->
<!---<cfinclude template="/code_lib/SCF_ActiveDirectory.cfc">

<cfset dn = getUserDNByAccountName('bfrick') />
<cfset x = getUserAttributesByDN(dn, "thumbnailPhoto,mail,cn,sn,objectclass,title,description,department,manager,wWWHomePage,displayName,member,dn,userAccountControl,homeDirectory,homeDrive,msExchHideFromAddressLists,givenName,initials,sn,userPrincipalName,sAMAccountName,whenChanged") />
<cfdump var="#x#" />--->





<!---<cfscript>
powershell = CreateObject("webservice", "http://scfcas/PowerShellService/?WSDL");
result = powershell.Invoke('add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
get-mailbox XXXTestXXX | out-string -width 10000
');
result;
</cfscript>
--->
<!---<cfset x = CreateObject("component", "#session.rootDir#.cfc.Termination").init(15) />
<Cfdump var="#x#" />--->

<!--- <cfset x = CreateObject("component", "#session.rootDir#.cfc.Termination").init(24) /> --->
<!--- <cfset util = CreateObject("component", "#session.rootDir#.cfc.utilities") /> --->
<!--- <cfinclude template="/code_lib/SCF_Employee.cfm">
<cfinclude template="/code_lib/SCF_Exchange.cfm">
<cfset x = SCF_Exchange_IsUserInDL( DL_List="SCF Primary Care",GUID=SESSION.myUserInfo.AD_GUID) /> --->

<!--- <Cfdump var="#util.funcCheckArchivedOU(x.EmployeeObj.FirstName, x.EmployeeObj.LastName)#" />
<cfdump var="#x#" expand="true" /> --->

<!--- <cfdump var="#x#" expand="false" />
<Cfdump var="#x.TerminationCompletion()#" /> --->
<!--- <Cfdump var="#x.HRDisable()#" /> --->
<!--- <Cfdump var="#x.TerminatinoCompletion()#" /> --->
<!--- <cfset x.ADDisable() /> --->
<!--- <cfdump var="#x.HomeFolderArchive()#" />
<Cfdump var="#x.EmailExport()#" /> --->
<!--- <cfdump var="#x.UserAccountDisable()#" /> --->

<!---  <cfdump var="#x.ADDisable()#" /> --->

<!---<cfdump var="#x.HomeFolderArchive()#" />

<cfdump var="#x.HRDisable()#"/>

<Cfdump var="#x.TimeKeeperDisable()#" />

<Cfdump var="#x.EmailExport()#" />

<Cfdump var="#x.RosettaDisable()#" />

<Cfdump var="#x.TerminatinoCompletion()#" /> --->

<!---<cfinclude template="/code_lib/SCF_ActiveDirectory.cfc">

<cfset dn = getUserDNByAccountName('MTestUser') />



<cfset sdn = getUserDNByAccountName('bfrick') />
<cfset x = getUserAttributesByDN(dn, "mail,cn,sn,objectclass,title,description,department,manager,wWWHomePage,displayName,member,dn,userAccountControl,homeDirectory,homeDrive,msExchHideFromAddressLists,givenName,initials,sn,userPrincipalName,sAMAccountName,whenChanged") />
<cfset replaceAttributesByDN( dn, 'wWWHomePage=http://mytest.com') />
<cfset replaceAttributesByDN( dn, 'manager=#sdn#') />
<cfset x = getUserAttributesByDN(dn, "mail,cn,sn,objectclass,title,description,department,manager,wWWHomePage,displayName,member,dn,userAccountControl,homeDirectory,homeDrive,msExchHideFromAddressLists,givenName,initials,sn,userPrincipalName,sAMAccountName,whenChanged") />
<cfdump var="#x#" />--->

 
<!--- <cfset attributelist="objectClass=top, person, organizationalPerson, user;
    telephonenumber=9079079077;
    mail=XXXTxxx@scf.cc; 
    ou=SCFUsers" /> 

<cfoutput> 

<cfldap action="add" 
    attributes="#attributeList#" 
    dn="CN=XXXTxxx, OU=SCF, ou=SCFUsers, dc=SouthcentralFoundation, dc=com" 
    server="10.100.1.101"
    username="scf\Userlist" 
    password="DefinedMan" >

</cfoutput> --->




<!---<cfscript>
powershell = CreateObject("webservice", "http://scfcas/PowerShellService/?WSDL");
result = powershell.Invoke('add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
get-mailbox DIsel | out-string -width 10000
');
writeDump(result);
</cfscript>
--->

<!---<cfset imgs = {
    "bfrick" = '\\SCFUserShare\Home\bfrick\Yoda_SWSB.jpg'
} />

<cfoutput>
    <cfloop collection="#imgs#" item="key">
       <cfscript>
            powershell = CreateObject("webservice", "http://scfcas/PowerShellService/?WSDL");
            result = powershell.Invoke('add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
            $user = Get-User "' & key & '" -ErrorAction SilentlyContinue;
            $FileData = [Byte[]]$(Get-Content -Path "' & imgs[key] & '" -Encoding Byte -ReadCount 0);
            $adsiuser = [ADSI]"LDAP://$($user.OriginatingServer)/$($user.DistinguishedName)";
            $adsiuser.Put("thumbnailPhoto", $FileData);
            $adsiuser.SetInfo();
            ');
        </cfscript>
    </cfloop>
</cfoutput>--->

<!---
<cfinclude template="/code_lib/SCF_ActiveDirectory.cfc">
<cfset dn = getUserDNByAccountName('DIsel') />
<cfset x = getUserAttributesByDN(dn, "thumbnailPhoto,cn,sn,ldapDisplayName,title,description") />
<cfdump var="#x#" />--->

<!---<cfscript>
powershell = CreateObject("webservice", "http://scfcas/PowerShellService/?WSDL");
result = powershell.Invoke('add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin
$user = Get-User "bfrick" -ErrorAction SilentlyContinue;
$FileData = [Byte[]]$(Get-Content -Path "\\SCFUserShare\Home\bfrick\token.jpg" -Encoding Byte -ReadCount 0);
$adsiuser = [ADSI]"LDAP://$($user.OriginatingServer)/$($user.DistinguishedName)";
$adsiuser.Put("thumbnailPhoto", $FileData);
$adsiuser.SetInfo();
');
/*result = powershell.Invoke('add-pssnapin Microsoft.Exchange.Management.PowerShell.Admin, Microsoft.Windows.AD
get-mailbox XXXTestXXX | out-string -width 10000
$photo = [byte[]](Get-Content \\SCFUserShare\Home\bficrk\token.jpg  -Encoding byte)
Set-ADUser bfrick -Replace @{thumbnailPhoto=$photo}
');*/
/*writeDump(result);*/
</cfscript>--->
<!---
<cfinclude template="/code_lib/SCF_ActiveDirectory.cfc">
<cfset dn = getUserDNByAccountName('bfrick') />
<cfset x = getUserAttributesByDN(dn, "thumbnailPhoto,cn,sn,ldapDisplayName,title,description") />
<cfdump var="#x#" />
<!---<cfset replaceAttributesByDN( dn, 'thumbnailPhoto=\\SCFUserShare\Home\bfrick\token.jpg') />--->
<!---<cfset replaceAttributesByDN( dn, 'thumbnailPhoto=#toBase64("\\SCFUserShare\Home\bfrick\token.jpg")#') />--->
<cfset x = getUserAttributesByDN(dn, "thumbnailPhoto,cn,sn,ldapDisplayName,title,description") />
<!---<cfset x = getUserAttributesByDN(dn, "thumbnailPhoto,cn,sn,ldapDisplayName,title,description,department,manager,wWWHomePage,displayName,member,dn,userAccountControl,homeDirectory,homeDrive,msExchHideFromAddressLists,givenName,initials,sn,userPrincipalName,sAMAccountName,whenChanged") />--->
<cfdump var="#ToBase64(x.thumbnailPhoto)#" />
<cffile action="readBinary" file="\\SCFUserShare\Home\bfrick\token.jpg" variable = "CopyOfPic"  />
<!---<cfdump var="#toString(CopyOfPic)#">--->
<!---<cfset replaceAttributesByDN( dn, 'thumbnailPhoto=#CopyOfPic#') />--->
--->




<!--- <cfquery name="FirstLook" datasource="RosettaProd">
SELECT     r.RosettaID, biw.BadgeNumber, biw.PhotoFileName, biw.CardType, iv.IDX, iv.PHOTO, iv.LAST_NAME, iv.FIRST_NAME
FROM         RosettaStone AS r INNER JOIN
                      Badge_IDWorks.Badges AS biw ON r.RosettaID = biw.RosettaID INNER JOIN
                      IVISPLUS.dbo.IVIS_DATA AS iv ON r.IVIS_IDX = iv.IDX
WHERE     (biw.PhotoFileName IS NULL)
</cfquery>
<cfset badgeworkpath = '\\scfappshare\ITS_Data\IDCentre\BadgePhotos\' />

<cfset photoarray = ArrayNew(2)>
                    
<cfloop query="FirstLook">
    <cfset photoarray[CurrentRow][1] = photo>
    <cfset photoarray[CurrentRow][2] = first_name>
    <cfset photoarray[CurrentRow][3] = last_name>
    <cfset photoarray[CurrentRow][5] = department>
    <cfset photoarray[CurrentRow][4] = company>
    <cfset photoarray[CurrentRow][6] = id_card_num>
    <cfset photoarray[CurrentRow][7] = idx>
    <cfset photoarray[CurrentRow][8] = RosettaID>
</cfloop>
<cfoutput>#FirstLook.RecordCount#</cfoutput>
<table width="100%" border='1'>
<tr>
<td>badge location</td>
<td>IDX</td>
<td>Card ID</td>
<td>Employee</td>
<td>RosettaID</td>
</tr>

<cfloop from="1" to="#FirstLook.RecordCount#" index="x">
<cftry>
        <cfoutput>
            <cfset folder = Right(photoarray[x][1],Len(photoarray[x][1])-1)>
            <cfset folder = Left(folder, Len(folder)-3)/500>
            <cfset picfolder = Int(folder)+1>
            <tr>
            <td>&nbsp;pic#picfolder#\#photoarray[x][1]#</td>            
            <td>&nbsp;#photoarray[x][7]#</td>
            <td>&nbsp;#photoarray[x][6]#</td>
            <td>&nbsp;#photoarray[x][2]# #photoarray[x][3]#</td>
            <td>&nbsp;#photoarray[x][8]#</td>
            </tr>
        </cfoutput>
<cfcatch type="Any" >

</cfcatch>
</cftry>

</cfloop>

</table> --->
